from MyClass.VoiceRecord import VoiceRecord
from python.module.VoiceRecognition import VoiceRecognition
from MyClass.chatbot import chatbot
#from MyClass.actions import actions
#from MyClass.mqtt import mqtt
from MyClass.baidu import baidu
import os
import time
import json
from python.module.VoiceRecognition import baidu
#from MyClass.memory import memory
#from MyClass.action import action
#import json


filename = '/home/pi/robot/audio.mp3'
#string_said = '跟我聊聊'
# bd = baidu()
# bd.reco()
# 
VC = VoiceRecord()
VC.rec()
# asr_string = ""
# 
# 
# name = "thread01"
# t = VoiceRecognition(name, "output_one_channel.wav")
# t.start()
# time.sleep(3)
# 
# asr_string = json.loads(t.asr_string)
# print("hello world{}".format(asr_string["payload"]["result"]))
#VC.voiceSpeech(filename,say_string)
#VC.playAudioMp3(filename)
#VC.mp3ConvertWav(filename)
#VC.playAudioPydub(filename)
#VC.changeAudioWave(filename)


#VC.voiceSpeech(filename,answer)
#os.system("sudo mpg123 audio.mp3")
#cd.saidBySkill(say_string)
#sentence = 'pick up something'
#cd.saidDeal(sentence)


#m = memory()
#response = 'PICK_U'
#result = m.getIntent(response)
#print(result)

#Act = actions()
#Act.pickUp()

#MQ = mqtt()


# cam = camera()
# #cd = chatbot()
# result = cam.detectPeople()
# print(cam.result_face)
# 
# 
# while True:
#     if cam.result_face:
#         VC = VoiceRecord()
#         VC.rec()
#         asr_string = ""
# 
#         name = "thread01"
#         t = VoiceRecognition(name, "output_one_channel.wav")
#         t.start()
#         time.sleep(3)
#         asr_string = json.loads(t.asr_string)
#         print("hello world{}".format(asr_string["payload"]["result"]))
#         result_words = asr_string["payload"]["result"]
#         #answer = cd.saidToAnswer(result_words)
#         print(answer)
#     else:
#         result = cam.detectPeople()
'''
while True:
    
    result = VC.voiceRecognize()
    MQ.upload("hello world")
    if result:
        answer = cd.saidToAnswer(result)
        print(answer)
        
        
        if ("PICK_UP") in answer:
            Act.pickUp()
            answer = "别忙着装逼了，你快点拿走，不然我要放回去了"
        VC.voiceSpeech(filename,answer)
        os.system("sudo mpg123 audio.mp3")
        
        if ("RELEASE") in answer:
            Act.release()
            answer = "我放开我可爱的手了，请拿好"
            VC.voiceSpeech(filename,answer)
            os.system("sudo mpg123 audio.mp3")
        
        if ("HEAD_DOWN") in answer:
            Act.headDown()
            answer = "对啊，总算是见面了，太不容易了，初次见面，往后多多想念"
            VC.voiceSpeech(filename,answer)
            os.system("sudo mpg123 audio.mp3")
            
        if ("TURN_LEFT") in answer:
            Act.turnLeft()
                        
         
        if ("TURN_RIGHT") in answer:
            Act.turnRight()
        
    MQ.upload("CLOSE_MOUTH")   
       
while True:
    say_string = input()
    cd = chatbot()
    #cd.saidAnswer(string_said)
    bot_id = '1016779'
    cd.saidBySkill(say_string,bot_id)


#print(stringsaid)
while True:
    string_said = input()
    cd = chatbot()
    response = cd.saidToAnswer(string_said)
    m = memory()
    result = m.getIntent(response)
    #juge if have memory in mysql
    if result == None:
        vc = voice()
        vc.voiceSpeech(filename,response)
    else:
        print("acting wait moment",result)
        a.actPick()
'''


